package com.hotec.PROJECT_NAME.modules.sys.mapper;

import com.hotec.PROJECT_NAME.modules.sys.entity.SysAccount;
import com.hotec.PROJECT_NAME.component.basic.BasicMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;
import java.util.Map;


/**
 * @author llb
 * @date
 */
public interface SysAccountMapper extends BasicMapper<SysAccount> {
    @SelectProvider(type = SysAccountMapper.RoleProvider.class, method = "queryAllWareHouseManager")
    List<Map<String, Object>> queryAllWareHouseManager();

    @SelectProvider(type = SysAccountMapper.RoleProvider.class, method = "queryUserWarranty")
    List<Map<String, Object>> queryUserWarranty(@Param("mobile") String mobile);

    class RoleProvider {
        public String queryAllWareHouseManager() {
            StringBuilder sb = new StringBuilder(
                    "SELECT  * FROM sys_account WHERE type_ = 'WAREHOUSE_MANAGEMENT' AND rep_warehouse_id is null;\n" +
                    "\n");
            return sb.toString();
        }

        public String queryUserWarranty(@Param("mobile") String mobile) {
            StringBuilder sb = new StringBuilder("SELECT a.type_ as type ,a.id,a.nickname,a.mobile,a.address,a.address_detail as addressDetail,b.id as warrantyCardId,b.card_code as cardCode,b.in_sn as inSn,b.out_sn as outSn,b.start_date as startDate,b.end_date as endDate FROM sys_account a LEFT JOIN warranty_card b ON a.id = b.owner_id  WHERE a.mobile  LIKE CONCAT('%', #{mobile},'%') ");
            return sb.toString();
        }
    }
}

